﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using XWord.Fundamental.Data.Impl;
using XWord.Fundamental.Domain;
using System.Collections;
using System.ComponentModel;

namespace XWord.GUI.View
{
    /// <summary>
    /// Interaction logic for PreFixView.xaml
    /// </summary>
    public partial class PreFixDemoView : Window
    {
        CategoryRepository rp;
        public PreFixDemoView()
        {
            InitializeComponent();
            rp = new CategoryRepository();
            EtymaRepository rp1 = new EtymaRepository();
            //Category cat = new Category();
            //cat.Name = "加强语气";
            //cat.CategoryType = CategoryType.PreFix;
            //rp.SaveCategory(cat);
            //var str=new string[]{"af","ag","al","an","ap","ar"};
            //foreach (var item in str)
            //{
            //    PreFix fix = new PreFix();
            //    fix.Name = item;
            //    fix.Comment = "加强语气";
            //    rp1.SaveEtyma(fix);
            //}
            
            CategoryList = rp.GetCategoryList(CategoryType.PreFix);
            EtymaList = rp1.GetEtymaList<Etymon>();
        }

        public IList<Etymon> EtymaList { get; set; }

        public IList<Category> CategoryList { get; set; }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Category cat = a.SelectedItem as Category;
            IList list = b.SelectedItems;
            foreach (var item in list)
            {
                cat.Etyma.Add(item);
                rp.SaveCategory(cat);
            }

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox box = sender as TextBox;
            string text = box.Text;
          b.Items.Filter = new Predicate<object>((obj) =>
            {
                var entity = obj as Etymon;
                return entity.Name.StartsWith(text);
            });
        }
    }
}
